package com.iona.servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.iona.json.JSONException;

public abstract class FeederServlet extends BaseServlet {

	private static final long serialVersionUID = 5159697089979337137L;

	@Override
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		setTransactional(false);
	}

	@Override
	public void doExecute(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException,
			JSONException {
		response.setContentType("application/json");
		response.setCharacterEncoding("UTF-8");
		Object doFeed = doFeed(request, response);
		final PrintWriter writer = response.getWriter();
		writer.print(doFeed);
		writer.close();
		writer.flush();
	}

	public abstract Object doFeed(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException,
			JSONException;

}
